﻿namespace PartyWithInheritance
{
    public class Party
    {
        public const int CostOfFoodPerPerson = 25;

        public int NumberOfPeople { get; set; }

        public bool FancyDecorations { get; set; }

        public virtual decimal Cost
        {
            get
            {
                var totalCost = CalculateCostOfDecorations();
                totalCost += CostOfFoodPerPerson * NumberOfPeople;

                if (NumberOfPeople > 12)
                {
                    totalCost += 100;
                }

                return totalCost;
            }
        }

        private decimal CalculateCostOfDecorations()
        {
            if (FancyDecorations)
            {
                return NumberOfPeople * 15M + 50M;
            }
            else
            {
                return NumberOfPeople * 7.5M + 30M;
            }
        }
    }

    public class DinnerParty:Party
    {
        public bool HealthyOption { get; set; }

        public DinnerParty(int numberOfPeople, bool fancyDecorations, bool healthyOption)
        {
            NumberOfPeople = numberOfPeople;
            FancyDecorations = fancyDecorations;
            HealthyOption = healthyOption;
        }

        public override decimal Cost
        {

            get
            {
                var totalCost = base.Cost;
                totalCost += CalculateCostOfBeveragesPerPerson() * NumberOfPeople;

                if (HealthyOption)
                {
                    totalCost *= 0.95M;
                }
                return totalCost;
            }
        }

        private decimal CalculateCostOfBeveragesPerPerson()
        {
            if (HealthyOption)
            {
                return 5M;
            }
            else
            {
                return 20M;
            }
        }
    }

    public class BirthdayParty:Party
    {
        public string CakeWriting { get; set; }

        public BirthdayParty(int numberOfPeople, bool fancyDecorations, string cakeWriting)
        {
            NumberOfPeople = numberOfPeople;
            FancyDecorations = fancyDecorations;
            CakeWriting = cakeWriting;
        }

        private int ActualLength => CakeWriting.Length > MaxWritingLength() ? MaxWritingLength() : CakeWriting.Length;

        private int CakeSize()
        {
            return NumberOfPeople <= 4 ? 8 : 16;
        }

        private int MaxWritingLength()
        {
            return CakeSize() == 8 ? 16 : 40;
        }

        public bool CakeWritingTooLong => CakeWriting.Length > MaxWritingLength();

        public override decimal Cost
        {
            get
            {
                var totalCost = base.Cost;

                decimal cakeCost;
                if (CakeSize() == 8)
                {
                    cakeCost = 40M + ActualLength * .25M;
                }
                else
                {
                    cakeCost = 75M + ActualLength * .25M;
                }

                return totalCost + cakeCost;
            }
        }
    }
}
